<template>
  <div class="layout-all">
    <el-tag type="success">总人数:{{child_data.team_num}}</el-tag>
      <el-tag type="success">销售额:{{child_data.team_amount}}</el-tag>
      <el-button type="primary" size="mini" style="margin-left:10px" @click="child_query({id:user_id})">业绩查询</el-button>
      <el-tree :data="child_data.list" accordion :props="defaultProps" >
        <div class="tree_item flex_row" slot-scope="{ node, data }">
            <div  @click.stop="">{{data.account}}</div>
            <el-tag>{{data.nickname}}</el-tag>
            <el-tag type="success">{{child_data.level[data.level_id-1]}}</el-tag>
            <el-tag type="primary" v-if="data.proxy_id>1">{{child_data.proxy[data.proxy_id-1]}}</el-tag>
            <el-tag v-if="data.child.length>0" type="warning">{{data.child.length}}</el-tag>
            <el-button type="primary" @click.stop="" size="mini" style="margin-left:10px" @click="child_query(data)">业绩查询</el-button>
        </div>
      </el-tree>

      <el-dialog :title="account+' 业绩'" :visible.sync="child_visible" :width="isMobile()?'100%':'20%'" :append-to-body="true">
        <el-tag>总业绩:{{count}}</el-tag>
        <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="date" label="日期" width="100"> </el-table-column>
        <el-table-column prop="ach_amount" label="业绩" > </el-table-column>
        </el-table>
      </el-dialog>
  </div>
</template>

<script>
export default {
  props:['user_id'],
  name:'TeamList',
  data() {
    return {
      child_visible:false,
      defaultProps: {
          children: 'child',
          label: 'account'
      },
      tableData: [],
      child_data: [],
      team_num: 0,
      team_amount: 0,
      count: 0,
      account: "",
    };
  },
  onShow(){

  },
  mounted() {
    this.onSearch();
  },
  methods: {
    onSearch() {
      this.get('shop/Order/child_index', {user_id:this.user_id}, 'POST').then(e => {
       this.child_data=e
      })
    },
    child_query(data) {
      this.account=data.account||''
      this.get('shop/Order/child_query', {user_id:data.id}, 'POST').then(e => {
        this.tableData=e.list
        this.count=0
        for(let i in e.list){
          this.count+=Number(e.list[i].ach_amount)
        }
         this.child_visible=true
      })
    },
  },
};
</script>

<style lang="scss">
.el-tree{
  .el-tree-node__content {
    height:60px ;
  }
}
</style>

<style scoped>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
.tree_item {
  font-size:14px;
  width:15%;
  justify-content: flex-start;
}

@media (max-width:550px) {
  .tree_item{
    width: 200px !important;
  }

}
</style>>
